package org.wizehack.mri.fl;

public class Tarantula implements SFLAlgorithm {

	@Override
	public double getSuspiciousness(int totalPassed, int totalFailed,
			int passed, int failed) {
		
		double suspiciousness = 0;
		double numerator = 0;
		
		if(totalFailed == 0){
			return 0;
		}
		else if(totalPassed == 0){
			return 1;
		}
		
		else{
			numerator = ((double)passed/(double)totalPassed) + ((double)failed/(double)totalFailed);
			if (numerator == 0){
				return 0;
			}
			else {
				suspiciousness = ((double)failed/(double)totalFailed) / (double)numerator;
			}
		}
		return suspiciousness;
	}
	/*
	public static void main(String[] args){
		Tarantula t = new Tarantula();
		double s = t.getSuspiciousness(5, 1, 1, 1);
		System.out.println(s);
	}
	 */
}
